package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags ="护理等级")
public class NursingLevelController extends BaseController{
    @Autowired
    private NursingLevelService nursingLevelService;
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult <List<NursingLevelVo>> findAll(){
        List<NursingLevelVo> vo=nursingLevelService.findAll();
        return success(vo);
    }
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult add(
            @ApiParam(value = "护理等级数据传输对象", required = true)
            @RequestBody NursingLevelDto dto){
        nursingLevelService.add(dto);
        return success();
    }
    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingLevelVo> pageResponse= nursingLevelService.getByPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult getById(@PathVariable Long id) {
        NursingLevelVo byId = nursingLevelService.getById(id);
        return success(byId);
    }
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteById(@PathVariable Long id) {
        nursingLevelService.deleteById(id);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改状态")
    public ResponseResult statueById(
            @ApiParam(value = "主键id")
            @PathVariable Long id,
            @ApiParam(value = "状态")
            @PathVariable Integer status) {
        nursingLevelService.statueById(id, status);
        return success();
    }
}
